﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Huirui.Cavan.Core.Persistent;
using Huirui.Cavan.Domain.MainBoundedContext.SearchModule;
using Huirui.Cavan.Core.MyLinq;

namespace Huirui.Cavan.Domain.MainBoundedContext.SystemModule
{
    public class CodeRulePropertySpecification : ISpecification<CodeRuleProperty, CodeRulePropertySearch>
    {
        #region ISpecification<CodeRuleProperty,CodeRulePropertySearch> Members

        public CodeRulePropertySearch SearchParams
        {
            get;
            set;
        }

        #endregion

        #region ISpecification<CodeRuleProperty> Members

        public System.Linq.Expressions.Expression<Func<CodeRuleProperty, bool>> Expression
        {
            get
            {
                IQueryBuilder<CodeRuleProperty> queryBuilder = QueryBuilder.Create<CodeRuleProperty>();

                if (null != SearchParams)
                {
                    if (SearchParams.CodeRuleID > 0)
                    {
                        queryBuilder = queryBuilder.Equals(crp => crp.CodeRuleID, SearchParams.CodeRuleID);
                    }
                    if (SearchParams.CodeRuleType > 0)
                    {
                        queryBuilder = queryBuilder.Equals(mch => mch.CodeRuleType, SearchParams.CodeRuleType);
                    }
                }

                return queryBuilder.Expression.Expand();
            }
        }

        #endregion
    }
}
